Repository navigation
Borrow lists Enum keeps using, and share defrustmod mappings through aliases - #18
Merged
Merged
Conversation
…opy kept slice items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets Figler write
Enum, pipes, and comprehensions instead of hand-written iterator chains, and drop 107 repeateddefrustmodlines.Enumfunctions took every owned list withinto_iter(), so a list used again, or borrowed by a value built from it (by_id = records_by_id(records)), did not compile. Blocks now lower knowing which variables later expressions use and what each binding was built from;Enumtakes a list only at its last use and otherwise iterates.iter(). Questions (any?,all?,count/2,empty?,sum) borrow regardless, items kept from a borrowed list (filter,reject,find,take,drop,reverse) are cloned, and numbers and atoms are copied out.HashSet.new()(andnew/with_capacity/defaultof the type a reference parameter names) passed where a reference is expected is borrowed.for record <- records, {:some, id} <- [record_id(record)], ...matches the value beside the item instead of building aVecper item, so it reads asfilter_map.defrustmodmappings are exported (__rustq_rust_modules__/0) and apply under any alias naming it;defrustmod __MODULE__, as: [...]maps the module itself. Aliases whose first segment names a RustQ module import it without waiting on nested modules the compiler may never define.I first tried casing nested segments as Rust modules (
Records.NodeChange→records::node_change), but Rust's casing is ambiguous there (PathBuilder.ArcSize.Largeis a type then a variant), so kiwi_codec will group its constants as associated constants instead (kiwi_records::NodeChange::GUID).Checked on Figler:
inherit_property_definitionsandrecords_by_idrewritten withEnum.any?,Enum.map, and a comprehension generate the same Rust as the hand-written chains (with&recordsinstead of&&records) and passcargo check.Follow-up from converting Figler:
binding.supersededfor a borrowedbinding) is never taken:Enumborrows it, and a comprehension copies its items, as it also does for an owned list still in use.Enum.filter/reject/find/countlower to.filter/.find(clippy'sunnecessary_filter_map), matching number and atom items as|&value|via a newAST.PatRef; slices iterate withiter()(into_iter_on_ref). Figler's generated crate passescargo clippy -D warnings.